//
//  ZYCApplianceRootViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/15.
//

#import "ZYCApplianceRootViewController.h"
#import "ZYCApplianceRootCell.h"
#import "ZYCApplianceRootHeaderView.h"
#import "ZYCNewsBulletinViewController.h"
#import "ZYCProtalNoticeListViewController.h"
#import "ZYCProtalCalendarViewController.h"
#import "ZYCManageDutyBulletinViewController.h"
#import "ZYCManageDutyRecordViewController.h"
#import "ZYCLectureRecordsListViewController.h"
#import "ZYCManageCourseRegistrationViewController.h"
#import "ZYCManageTourStatisticsViewController.h"
#import "ZYCManageTourRecordViewController.h"
#import "ZYCManageStuAttendViewController.h"
#import "ZYCManageTeachAttendViewController.h"
#import "ZYCTeacherDiningViewController.h"
#import "ZYCTeachingTeachLearningViewController.h"
#import "ZYCTeachingAttendanceViewController.h"
#import "ZYCEducationGrowthFileViewController.h"
#import "ZYCSourceWisdonCenterViewController.h"
#import "ZYCStuLeaveRecordRootViewController.h"
#import "ZYCApplianceBannerView.h"
#import "ZYCWheelBannerModel.h"
#import "ZYCNoDataView.h"
#import "ZYCApplianceRootModel.h"
#import "ZYCCommonBaseModel.h"
#import "ZYCCourseStudentModel.h"
#import "ZYCManageCourseSelectViewController.h"
#import "ZYCGrowthFileParentViewController.h"
#import "ZYCBannaerViewController.h"
#import "NSString+File.h"

@interface ZYCApplianceRootViewController ()<UINavigationControllerDelegate,UICollectionViewDataSource,UICollectionViewDelegate,ZYCApplianceBannerViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic,strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSArray *teacherArray;
@property (nonatomic, strong) NSArray *parentArray;
@property (nonatomic, strong) NSMutableArray *tempArray;
@property (nonatomic, copy) NSString *roleType;
@property (nonatomic, strong) ZYCNoDataView *noDataView;
@property (nonatomic, assign) ZYCLoginRoleType type;

@property (nonatomic, strong) NSArray *wheelBannerArray;
@property (nonatomic, strong) NSArray *authorityArray;
@end

@implementation ZYCApplianceRootViewController

#pragma mark - 生命周期函数
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.collectionView];
    //轮播图
    [self loadBanner];
    // 获取学期列表
    [self querySemesterList];
    //获取课程列表
    [self queryCourseList];
    // 获取年级列表
    [self queryGradeList];
    // 获取班级列表
    [self queryClassList];
    // 获取听评课学科
    [self querySubjectList];
    // 获取听评课类型
    [self queryListenClassList];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    NSInteger roleType =  [[NSUserDefaults standardUserDefaults] integerForKey:@"kUserRoleType"];
    if (roleType  == 0) {//教师
        self.roleType = @"1";
        NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *path = [documentPath stringByAppendingPathComponent:@"authority.data"];;
        NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
        self.authorityArray = array;

        self.dataSource = [NSArray yy_modelArrayWithClass:[ZYCApplianceRootModel class] json:self.teacherArray].mutableCopy;
        for (ZYCApplianceRootModel *section in self.dataSource) {
            NSInteger col = section.children.count / 4; //行数
            NSInteger row = section.children.count % 4; //列数
            if (row != 0) {
                NSMutableArray *temp = [NSMutableArray arrayWithCapacity:0];
                for (NSInteger i = 0; i < (col + 1) * 4; i++) {
                    if (i < section.children.count) {
                        [temp addObject:section.children[i]];
                    }else{
                        ZYCApplianceRootModel *m = [ZYCApplianceRootModel new];
                        m.menuName = @"test";
                        m.menuId = @"test";
                        [temp addObject:m];
                    }
                }
                section.children = temp;
            }
        }
        [self.collectionView reloadData];
    }else{
        self.dataSource = [NSArray yy_modelArrayWithClass:[ZYCApplianceRootModel class] json:self.parentArray].mutableCopy;
        for (ZYCApplianceRootModel *section in self.dataSource) {
            NSInteger col = section.children.count / 4; //行数
            NSInteger row = section.children.count % 4; //列数
            if (row != 0) {
                NSMutableArray *temp = [NSMutableArray arrayWithCapacity:0];
                for (NSInteger i = 0; i < (col + 1) * 4; i++) {
                    if (i < section.children.count) {
                        [temp addObject:section.children[i]];
                    }else{
                        ZYCApplianceRootModel *m = [ZYCApplianceRootModel new];
                        m.menuName = @"test";
                        m.menuId = @"test";
                        [temp addObject:m];
                    }
                }
                section.children = temp;
            }
        }
        [self.collectionView reloadData];
    }
}

#pragma mark - 网络请求
- (void)loadBanner{
    [[URLManager sharedURLManager] getUrlString:Home_Get_QueryPics requestService:RequestServiceWorkBench parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(id  _Nullable responseObject) {
            if (SUCCESS(responseObject[@"code"])) {
                NSArray *wheelBanner = [NSArray yy_modelArrayWithClass:[ZYCWheelBannerModel class] json:responseObject[@"body"]];
                self.wheelBannerArray = wheelBanner;
                [self.collectionView reloadData];
            }else{
                [MrjToast makeToast:responseObject[@"message"] makeView:self.view];
            }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}

/*   -------------公共接口----------------*/
// 获取班级列表
- (void)queryClassList{
    [[URLManager sharedURLManager] getUrlString:Common_Get_QueryClassList requestService:RequestServiceWorkBench parameters:nil progress:nil success:^(id  _Nullable responseObject) {
        if (SUCCESS(responseObject[@"code"])) {
           NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCommonBaseModel class] json:responseObject[@"body"]];
            NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
            NSString *path = [documentPath stringByAppendingPathComponent:@"class.data"];
            [NSKeyedArchiver archiveRootObject:array toFile:path];
        }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}

// 获取年级列表
- (void)queryGradeList{
    [[URLManager sharedURLManager] getUrlString:Common_Get_QueryGradeList requestService:RequestServiceWorkBench parameters:nil progress:nil success:^(id  _Nullable responseObject) {
        if (SUCCESS(responseObject[@"code"])) {
            NSMutableArray *temp = [NSMutableArray arrayWithCapacity:0];
            ZYCCommonBaseModel *first = [[ZYCCommonBaseModel alloc] init];
            first.name = @"全部年级";
            first.nameId = @"";
            [temp addObject:first];
           NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCommonBaseModel class] json:responseObject[@"body"]];
            NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documentPath stringByAppendingPathComponent:@"grade.data"];
            [temp addObjectsFromArray:array];
            [NSKeyedArchiver archiveRootObject:temp toFile:path];
        }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}

//获取学期列表
- (void)querySemesterList{
    [[URLManager sharedURLManager] getUrlString:Common_Get_QuerySemesterList requestService:RequestServiceWorkBench parameters:nil progress:nil success:^(id  _Nullable responseObject) {
        if (SUCCESS(responseObject[@"code"])) {
            NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCommonBaseModel class] json:responseObject[@"body"]];
            NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documentPath stringByAppendingPathComponent:@"semester.data"];
            [NSKeyedArchiver archiveRootObject:array toFile:path];
        }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}

//获取课程列表
- (void)queryCourseList{
    [[URLManager sharedURLManager] getUrlString:Common_Get_QueryCourseList requestService:RequestServiceWorkBench parameters:nil progress:nil success:^(id  _Nullable responseObject) {
        if (SUCCESS(responseObject[@"code"])) {
            NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCommonBaseModel class] json:responseObject[@"body"]];
            NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documentPath stringByAppendingPathComponent:@"course.data"];
            [NSKeyedArchiver archiveRootObject:array toFile:path];
        }
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//获取听评课类型(听评课)
- (void)queryListenClassList{
    [[URLManager sharedURLManager] getUrlString:Common_Get_QueryListenClassTypeList requestService:RequestServiceWorkBench parameters:nil progress:nil success:^(id  _Nullable responseObject) {
        if (SUCCESS(responseObject[@"code"])) {
            NSMutableArray *temp = [NSMutableArray array];
            ZYCCommonBaseModel *firstModel = [ZYCCommonBaseModel new];
            firstModel.name = @"类型";
            firstModel.nameId = @"";
            [temp addObject:firstModel];
            NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCommonBaseModel class] json:responseObject[@"body"]];
            [temp addObjectsFromArray:array];
            NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documentPath stringByAppendingPathComponent:@"listenClass.data"];
            [NSKeyedArchiver archiveRootObject:temp toFile:path];
        }
    } failure:^(NSError * _Nonnull error) {
        
    }];
}
// 获取学科(听评课)
- (void)querySubjectList{
    [[URLManager sharedURLManager] getUrlString:Common_Get_QuerySubjectList requestService:RequestServiceWorkBench parameters:nil progress:nil success:^(id  _Nullable responseObject) {
        if (SUCCESS(responseObject[@"code"])) {
            NSMutableArray *temp = [NSMutableArray array];
            ZYCCommonBaseModel *firstModel = [ZYCCommonBaseModel new];
            firstModel.name = @"学科";
            firstModel.nameId = @"";
            [temp addObject:firstModel];
            NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCommonBaseModel class] json:responseObject[@"body"]];
            [temp addObjectsFromArray:array];
            NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documentPath stringByAppendingPathComponent:@"subject.data"];
            [NSKeyedArchiver archiveRootObject:temp toFile:path];
        }
    } failure:^(NSError * _Nonnull error) {
        
    }];
}




#pragma mark - UICollectionViewDataSource && UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return self.dataSource.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    ZYCApplianceRootModel *model = self.dataSource[section];
    return model.children.count;
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ZYCApplianceRootCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([ZYCApplianceRootCell class]) forIndexPath:indexPath];
    ZYCApplianceRootModel *section = self.dataSource[indexPath.section];
    cell.model = section.children[indexPath.item];
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    UIBezierPath *maskPath = nil;
    CGRect boardRect;
    float h = cell.bounds.size.height;
    float w = cell.bounds.size.width;
    ZYCApplianceRootModel *section =  self.dataSource[indexPath.section];
    NSInteger col = section.children.count / 4; //行数
    if (col == 1) {// 一行
        if (indexPath.item == 0) {
            //左上
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if (indexPath.item + 1 == 4){
            //右上
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else{
            //其余的渲染不加角
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [UIBezierPath bezierPathWithRect:boardRect];
        }
    }else if(col == 2){ //两行
        if (indexPath.item == 0) {
            //左上
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if (indexPath.item + 1 == 4){
            //右上
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopRight  cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if(indexPath.item + 1 == 5){
            //左下
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if(indexPath.item + 1 ==  8){
            //右下
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else{
            //其余的渲染不加角
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [UIBezierPath bezierPathWithRect:boardRect];
        }
    }else{// 其他
        if (indexPath.item == 0) {
            //左上
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if (indexPath.item + 1 == 4){
            //右上
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopRight  cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if(indexPath.item + 1 == 9){
            //左下
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else if(indexPath.item + 1 ==  12){
            //右下
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(7.5, 7.5)] bezierPathByReversingPath];
        }else{
            //其余的渲染不加角
            boardRect = CGRectMake(0, -1, w, h);
            maskPath = [UIBezierPath bezierPathWithRect:boardRect];
        }
    }
    for (int i = 0; i < cell.contentView.layer.sublayers.count; i++) {
        CALayer *layer = cell.contentView.layer.sublayers[i];
        if ([layer.name isEqualToString:@"maskLayer"]) {
            [layer removeFromSuperlayer];
        }
    }
    //填充颜色和划线
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.name = @"maskLayer";
    maskLayer.frame = boardRect;
    maskLayer.path = maskPath.CGPath;
    maskLayer.lineWidth = 0.0f;
    maskLayer.fillColor = [UIColor whiteColor].CGColor;
    maskLayer.masksToBounds = YES;
    [cell.contentView.layer insertSublayer:maskLayer atIndex:0];
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    ZYCApplianceRootModel *section = self.dataSource[indexPath.section];
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        if ([section.menuName  isEqualToString:@"智慧门户"]) {
            ZYCApplianceBannerView *header = nil;
            header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([ZYCApplianceBannerView class]) forIndexPath:indexPath];
            header.section = section.menuName;
            header.wheelBannerList = self.wheelBannerArray;
            header.delegate = self;
            return header;
        }else{
            ZYCApplianceRootHeaderView *header = nil;
            header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([ZYCApplianceRootHeaderView class]) forIndexPath:indexPath];
            header.section = section.menuName;
            return header;
        }

    }
    return nil;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:NO];
    ZYCApplianceRootModel *section = self.dataSource[indexPath.section];
    NSArray *child = section.children;
    ZYCApplianceRootModel *model =  child[indexPath.item];
    NSInteger roleType =  [[NSUserDefaults standardUserDefaults] integerForKey:@"kUserRoleType"];
    if (roleType  == 0) {//教师
        if ([model.menuId isEqualToString:@"540759249913018"] && [self.authorityArray containsObject:@"540759249913018"]) {//新闻
            ZYCNewsBulletinViewController *vc = [ZYCNewsBulletinViewController new];
            vc.type = ZYCNewsBulletinTypeNews;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913019"] && [self.authorityArray containsObject:@"540759249913019"]) {//公告
            ZYCNewsBulletinViewController *vc = [ZYCNewsBulletinViewController new];
            vc.type = ZYCNewsBulletinTypeBulletiin;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913020"] && [self.authorityArray containsObject:@"540759249913020"]) {//通知
            ZYCProtalNoticeListViewController *vc = [ZYCProtalNoticeListViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913081"] && [self.authorityArray containsObject:@"540759249913081"]) {//周历
            ZYCProtalCalendarViewController *vc = [ZYCProtalCalendarViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913028"] && [self.authorityArray containsObject:@"540759249913028"]) {//值班报告
            ZYCManageDutyBulletinViewController *vc = [ZYCManageDutyBulletinViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913022"] && [self.authorityArray containsObject:@"540759249913022"]) {//值班记录
            ZYCManageDutyRecordViewController *vc = [ZYCManageDutyRecordViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913023"] && [self.authorityArray containsObject:@"540759249913023"]) {// 选课报名
            ZYCManageCourseRegistrationViewController *vc = [ZYCManageCourseRegistrationViewController new];
            vc.enterType = ZYCCourseRegistrationEnterApplianceCourseRegister;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913029"] && [self.authorityArray containsObject:@"540759249913029"]) {//授课记录
            ZYCLectureRecordsListViewController *vc = [ZYCLectureRecordsListViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913030"] && [self.authorityArray containsObject:@"540759249913030"]) {//巡堂统计
            ZYCManageTourStatisticsViewController *vc = [ZYCManageTourStatisticsViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913024"] && [self.authorityArray containsObject:@"540759249913024"]) {//巡堂记录
            ZYCManageTourRecordViewController *vc = [ZYCManageTourRecordViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913031"] && [self.authorityArray containsObject:@"540759249913031"]) {//学生考勤
            ZYCManageStuAttendViewController *vc = [ZYCManageStuAttendViewController new];
            vc.authorityArray = self.authorityArray;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913173"] && [self.authorityArray containsObject:@"540759249913173"]) {//教师考勤
            ZYCManageTeachAttendViewController *vc = [ZYCManageTeachAttendViewController new];
            vc.authorityArray = self.authorityArray;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913032"] && [self.authorityArray containsObject:@"540759249913032"]) {//教师就餐
            ZYCTeacherDiningViewController *vc = [ZYCTeacherDiningViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913166"] && [self.authorityArray containsObject:@"540759249913166"]) {//评教评学
            ZYCTeachingTeachLearningViewController *vc = [ZYCTeachingTeachLearningViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913165"] && [self.authorityArray containsObject:@"540759249913165"]) {//听评课
            ZYCTeachingAttendanceViewController *vc = [ZYCTeachingAttendanceViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if([model.menuId isEqualToString:@"540759249913167"] && [self.authorityArray containsObject:@"540759249913167"]){//成长档案
            ZYCEducationGrowthFileViewController *vc = [ZYCEducationGrowthFileViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if([model.menuId isEqualToString:@"540759249913168"] && [self.authorityArray containsObject:@"540759249913168"]){//资源中心
            ZYCSourceWisdonCenterViewController *vc = [ZYCSourceWisdonCenterViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [self tipShow];
        }
    }else{ // 家长端
        if ([model.menuId isEqualToString:@"540759249913018"]) {//新闻
            ZYCNewsBulletinViewController *vc = [ZYCNewsBulletinViewController new];
            vc.type = ZYCNewsBulletinTypeNews;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913019"]) {//公告
            ZYCNewsBulletinViewController *vc = [ZYCNewsBulletinViewController new];
            vc.type = ZYCNewsBulletinTypeBulletiin;
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913020"]) {//通知
            ZYCProtalNoticeListViewController *vc = [ZYCProtalNoticeListViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if([model.menuId isEqualToString:@"540759249913023"]){//选课报名
            ZYCManageCourseRegistrationViewController *vc = [ZYCManageCourseRegistrationViewController new];
            vc.enterType = ZYCCourseRegistrationEnterApplianceCourseRegister;
            [self.navigationController pushViewController:vc animated:YES];
        }else if([model.menuId isEqualToString:@"540759249913159"]){ // 请假记录
            ZYCStuLeaveRecordRootViewController *vc = [ZYCStuLeaveRecordRootViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if([model.menuId isEqualToString:@"540759249913157"]){ // 考勤记录
            ZYCManageCourseRegistrationViewController *vc = [ZYCManageCourseRegistrationViewController new];
            vc.enterType = ZYCCourseRegistrationEnterApplianceStuAttendance;//学生考勤
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([model.menuId isEqualToString:@"540759249913166"]) {//评教评学
            ZYCTeachingTeachLearningViewController *vc = [ZYCTeachingTeachLearningViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if([model.menuId isEqualToString:@"540759249913167"]){//成长档案
            ZYCGrowthFileParentViewController *vc = [[ZYCGrowthFileParentViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }


}

- (void)tipShow{
    [MrjToast makeToast:@"暂无权限访问" makeView:self.view];
}

// 获取所有学生
- (void)judegeMyStudentCount{
    [[URLManager sharedURLManager] getUrlString:Appliance_Get_getMyStudents requestService:RequestServiceWorkBench parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(id  _Nullable responseObject) {
            if (SUCCESS(responseObject[@"code"])) {
                NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCourseStudentModel class] json:responseObject[@"body"]];
                if (array.count > 1) {
                    ZYCManageCourseRegistrationViewController *vc = [ZYCManageCourseRegistrationViewController new];
                    vc.enterType = ZYCCourseRegistrationEnterApplianceCourseRegister;
                    [self.navigationController pushViewController:vc animated:YES];
                }else{
                    ZYCManageCourseSelectViewController *vc = [ZYCManageCourseSelectViewController new];
                    vc.titleString = @"选课报名";
                    ZYCCourseStudentModel *model = array.firstObject;
                    vc.scope = model.scope;
                    vc.studentId = model.s_id;
                    vc.studentName = model.name;
                    [self.navigationController pushViewController:vc animated:YES];
                }
      
            }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return CGSizeMake(kScreenWidth, (kScreenWidth - 20) / (710 / 300) + 74.0f);
    }
    return CGSizeMake(kScreenWidth, 44.0f);
}


#pragma mark - getters

- (NSArray *)authorityArray {
    if (!_authorityArray) {
        _authorityArray = [[NSArray alloc] init];
    }
    return _authorityArray;
}
- (NSArray *)parentArray{
    if (!_parentArray) {
         NSString *filePath = [[NSBundle mainBundle] pathForResource:@"ApplicationMenu.plist" ofType:nil];
        _parentArray = [NSArray arrayWithContentsOfFile:filePath];
    }
    return _parentArray;
}

- (NSArray *)teacherArray{
    if (!_teacherArray) {
         NSString *filePath = [[NSBundle mainBundle] pathForResource:@"teacherApplicationMenu.plist" ofType:nil];
        _teacherArray = [NSArray arrayWithContentsOfFile:filePath];
    }
    return _teacherArray;
}

- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataSource;
}
- (ZYCNoDataView *)noDataView {
    if (!_noDataView) {
        _noDataView = [[ZYCNoDataView alloc] initWithFrame:self.collectionView.frame];
        _noDataView.hidden = YES;
        [self.view addSubview:_noDataView];
    }
    return _noDataView;
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight -kTabBarHeight) collectionViewLayout:self.layout];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.scrollEnabled = YES;
        _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [_collectionView registerClass:[ZYCApplianceRootCell class]            forCellWithReuseIdentifier:NSStringFromClass([ZYCApplianceRootCell class])];
        [_collectionView registerClass:[ZYCApplianceRootHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([ZYCApplianceRootHeaderView class])];
        [_collectionView registerClass:[ZYCApplianceBannerView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([ZYCApplianceBannerView class])];
        _collectionView.showsVerticalScrollIndicator = NO;
    }
    return _collectionView;
}

- (UICollectionViewFlowLayout *)layout{
    if (!_layout) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        CGFloat w = (kScreenWidth - 18 ) / 4;
        _layout.itemSize = CGSizeMake(w,w + 20);
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _layout.minimumLineSpacing = -1.0f;//行间距
        _layout.minimumInteritemSpacing = -1.0f;//列间距
        _layout.sectionInset = UIEdgeInsetsMake(0, 9.0f, 0, 9.0f);
    }
    return _layout;
}

- (NSArray *)wheelBannerArray {
    if (!_wheelBannerArray) {
        _wheelBannerArray = [[NSArray alloc] init];
    }
    return _wheelBannerArray;
}


#pragma mark - ZYCApplianceBannerViewDelegate

- (void)applianceBannerViewDidClickBanner:(ZYCWheelBannerModel *)model{
    if ([[self getCompleteWebsite:model.linkUrl] isUrlString]) {
        ZYCBannaerViewController *vc = [[ZYCBannaerViewController alloc] init];
        vc.model = model;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark - UINavigationControllerDelegate
-(void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:[viewController isKindOfClass:[self class]] animated:YES];
}

- (NSString *)getCompleteWebsite:(NSString *)urlStr{
    NSString *returnUrlStr = nil;
    NSString *scheme = nil;
    assert(urlStr != nil);
    urlStr = [urlStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if ( (urlStr != nil) && (urlStr.length != 0) ) {
        NSRange  urlRange = [urlStr rangeOfString:@"://"];
        if (urlRange.location == NSNotFound) {
            returnUrlStr = [NSString stringWithFormat:@"http://%@", urlStr];
        } else {
            scheme = [urlStr substringWithRange:NSMakeRange(0, urlRange.location)];
            assert(scheme != nil);
            if ( ([scheme compare:@"http"  options:NSCaseInsensitiveSearch] == NSOrderedSame)
                || ([scheme compare:@"https" options:NSCaseInsensitiveSearch] == NSOrderedSame) ) {
                returnUrlStr = urlStr;
            } else {
                //不支持的URL方案
            }
        }
    }
    return returnUrlStr;
}


- (void)dealloc{
    self.navigationController.delegate = nil;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
